/*
 * Copyright (c) 1997 - 2012 Rakuten, Inc. All Rights Reserved.
 * $Id$
 * Created on 2012/05/24
 */
package com.rakuten.api.mule.model;

import java.util.Date;
import java.util.List;
import java.util.Map;
import org.codehaus.jackson.annotate.JsonIgnore;
import org.codehaus.jackson.annotate.JsonProperty;
import org.codehaus.jackson.annotate.JsonPropertyOrder;

/**
 *
 * @author hayatsu
 */
@JsonPropertyOrder({
	"itemVariantId",
	"itemId",
	"sku",
	"gran",
	"upc",
	"ean",
	"jan",
	"gtin",
	"apn",
	"isbn",
	"issn",
	"modelNumber",
	"inactiveTime",
	"shippingWeight",
	"shippingDimension",
	"purchaseLimit",
	"images",
	"shopInfo"
})
public class ItemVariant{
	private String itemVariantId;
	private String itemId;
	@JsonIgnore
	private int sequence;
	private String sku;
	private String gran;
	private String upc;
	private String ean;
	private String jan;
	private String gtin;
	private String apn;
	private String isbn;
	private String issn;
	private String modelNumber;
	private Date inactiveTime;
	private ItemWeight shippingWeight;
	private ItemDimension shippingDimension;
	private Integer purchaseLimit;
	private List<ItemImage> images;

	//key=shopId
	@JsonProperty("shopInfo")
	private Map<String, ShopInfo> shopInfoMap;

	private List<MultiLang> variantValues;
	@Deprecated
	@JsonIgnore
	private List<ItemVariantDetail> details;

	public int getSequence(){
		return sequence;
	}

	public void setSequence(int sequence){
		this.sequence=sequence;
	}

	public String getApn(){
		return apn;
	}

	public void setApn(String apn){
		this.apn=apn;
	}

	@Deprecated
	public List<ItemVariantDetail> getDetails(){
		return details;
	}

	@Deprecated
	public void setDetails(List<ItemVariantDetail> details){
		this.details=details;
	}

	public ItemDimension getShippingDimension(){
		return shippingDimension;
	}

	public void setShippingDimension(ItemDimension shippingDimension){
		this.shippingDimension=shippingDimension;
	}

	public String getEan(){
		return ean;
	}

	public void setEan(String ean){
		this.ean=ean;
	}

	public String getGran(){
		return gran;
	}

	public void setGran(String gran){
		this.gran=gran;
	}

	public Integer getPurchaseLimit() {
		return purchaseLimit;
	}

	public void setPurchaseLimit(Integer purchaseLimit) {
		this.purchaseLimit = purchaseLimit;
	}	
	
	public List<ItemImage> getImages(){
		return images;
	}

	public void setImages(List<ItemImage> images){
		this.images=images;
	}

	public Date getInactiveTime(){
		return inactiveTime;
	}

	public void setInactiveTime(Date inactiveTime){
		this.inactiveTime=inactiveTime;
	}

	public String getIsbn(){
		return isbn;
	}

	public void setIsbn(String isbn){
		this.isbn=isbn;
	}

	public String getIssn(){
		return issn;
	}

	public void setIssn(String issn){
		this.issn=issn;
	}

	public String getItemId(){
		return itemId;
	}

	public void setItemId(String itemId){
		this.itemId=itemId;
	}

	public String getItemVariantId(){
		return itemVariantId;
	}

	public void setItemVariantId(String itemVariantId){
		this.itemVariantId=itemVariantId;
	}

	public String getJan(){
		return jan;
	}

	public void setJan(String jan){
		this.jan=jan;
	}

	public String getModelNumber(){
		return modelNumber;
	}

	public void setModelNumber(String modelNumber){
		this.modelNumber=modelNumber;
	}

	public Map<String, ShopInfo> getShopInfoMap(){
		return shopInfoMap;
	}

	public void setShopInfoMap(Map<String, ShopInfo> shopInfoMap){
		this.shopInfoMap=shopInfoMap;
	}

	public boolean isShopVisible(String shopId, long currentTimeMillis){
		if(shopInfoMap==null) return false;
		ShopInfo info=shopInfoMap.get(shopId);
		if(info==null) return false;
		ItemDuration dur=info.getDuration();
		return dur!=null&&dur.isLive(currentTimeMillis);
	}

	public ShopInfo getShopInfo(String shopId){
		return shopInfoMap==null?null:shopInfoMap.get(shopId);
	}

	public ShopInfo getOrCreateShopInfo(String shopId){
		if(shopInfoMap==null) shopInfoMap=new java.util.HashMap<>();
		ShopInfo ret=shopInfoMap.get(shopId);
		if(ret==null) shopInfoMap.put(shopId, ret=new ShopInfo());
		return ret;
	}

	public String getSku(){
		return sku;
	}

	public void setSku(String sku){
		this.sku=sku;
	}

	public String getGtin(){
		return gtin;
	}

	public void setGtin(String gtin){
		this.gtin=gtin;
	}

	public String getUpc(){
		return upc;
	}

	public void setUpc(String upc){
		this.upc=upc;
	}

	public ItemWeight getShippingWeight(){
		return shippingWeight;
	}

	public void setShippingWeight(ItemWeight shippingWeight){
		this.shippingWeight=shippingWeight;
	}

	public List<MultiLang> getVariantValues(){
		return variantValues;
	}

	public void setVariantValues(List<MultiLang> variantValues){
		this.variantValues=variantValues;
	}


	public static class ShopInfo{
		private ItemDuration duration;
		private List<ItemPricing> pricings;

		public ItemDuration getDuration(){
			return duration;
		}

		public void setDuration(ItemDuration duration){
			this.duration=duration;
		}

		public List<ItemPricing> getPricings(){
			return pricings;
		}

		public void setPricings(List<ItemPricing> pricings){
			this.pricings=pricings;
		}

	}
}
